package cc.rengu.igas.momp.biz.service.impl;

import cc.rengu.igas.momp.common.enums.MompTxnNumEnum;
import cc.rengu.igas.momp.common.enums.RespCodeEnum;
import cc.rengu.igas.momp.facade.EditMcDetailService;
import cc.rengu.igas.momp.facade.request.*;
import cc.rengu.igas.momp.facade.response.*;
import cc.rengu.igas.momp.facade.result.Result;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.DubboResult;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;

/**
 * 营销活动信息编辑接口实现
 *
 * @author Jinan Liu
 * @version 1.0.0
 * @date 2020/3/16 10:09
 */
@SuppressWarnings({"unchecked"})
public class EditMcDetailInfoServiceImpl implements EditMcDetailService {

    /**
     * 代理商营销活动信息编辑接口Dubbo实现
     *
     * @param editAgentProfitSharingMcDetailRequest 代理商营销活动信息编辑接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.EditAgentProfitSharingMcDetailResponse>
     * @author Jinan Liu
     * @date 2020/5/20 15:44
     */
    @Override
    public Result<EditAgentProfitSharingMcDetailResponse> editAgentProfitSharingMcDetail(EditAgentProfitSharingMcDetailRequest editAgentProfitSharingMcDetailRequest) {

        DubboService<EditAgentProfitSharingMcDetailRequest> dubboService = new DubboServiceImpl();
        Result<EditAgentProfitSharingMcDetailResponse> editAgentProfitSharingMcDetailResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.EDIT_APS_MC_DETAIL.getTxnNum().equals(editAgentProfitSharingMcDetailRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<EditAgentProfitSharingMcDetailResponse> dubboResult = dubboService.callAtomService(editAgentProfitSharingMcDetailRequest,
                    MompTxnNumEnum.EDIT_APS_MC_DETAIL.getService(), EditAgentProfitSharingMcDetailResponse.class);
            editAgentProfitSharingMcDetailResponseResult.setResult(dubboResult.getResult());
            editAgentProfitSharingMcDetailResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            EditAgentProfitSharingMcDetailResponse editAgentProfitSharingMcDetailResponse = new EditAgentProfitSharingMcDetailResponse();
            editAgentProfitSharingMcDetailResponseResult.setResult(editAgentProfitSharingMcDetailResponse);
            editAgentProfitSharingMcDetailResponse.setHeader(editAgentProfitSharingMcDetailRequest.getHeader());
            editAgentProfitSharingMcDetailResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                editAgentProfitSharingMcDetailResponse.setRespCode(((BizException) e).getCode());
                editAgentProfitSharingMcDetailResponse.setRespDesc(e.getMessage());
            } else {
                editAgentProfitSharingMcDetailResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                editAgentProfitSharingMcDetailResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return editAgentProfitSharingMcDetailResponseResult;
    }

    /**
     * 收银员返现营销活动信息编辑接口Dubbo实现
     *
     * @param editCashierCashbackMcDetailRequest 收银员返现营销活动信息编辑接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.EditCashierCashbackMcDetailResponse>
     * @author Jinan Liu
     * @date 2020/5/20 15:46
     */
    @Override
    public Result<EditCashierCashbackMcDetailResponse> editCashierCashbackMcDetail(EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest) {

        DubboService<EditCashierCashbackMcDetailRequest> dubboService = new DubboServiceImpl();
        Result<EditCashierCashbackMcDetailResponse> editCashierCashbackMcDetailResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.EDIT_CCB_MC_DETAIL.getTxnNum().equals(editCashierCashbackMcDetailRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<EditCashierCashbackMcDetailResponse> dubboResult = dubboService.callAtomService(editCashierCashbackMcDetailRequest,
                    MompTxnNumEnum.EDIT_CCB_MC_DETAIL.getService(), EditCashierCashbackMcDetailResponse.class);
            editCashierCashbackMcDetailResponseResult.setResult(dubboResult.getResult());
            editCashierCashbackMcDetailResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            EditCashierCashbackMcDetailResponse editCashierCashbackMcDetailResponse = new EditCashierCashbackMcDetailResponse();
            editCashierCashbackMcDetailResponseResult.setResult(editCashierCashbackMcDetailResponse);
            editCashierCashbackMcDetailResponse.setHeader(editCashierCashbackMcDetailRequest.getHeader());
            editCashierCashbackMcDetailResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                editCashierCashbackMcDetailResponse.setRespCode(((BizException) e).getCode());
                editCashierCashbackMcDetailResponse.setRespDesc(e.getMessage());
            } else {
                editCashierCashbackMcDetailResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                editCashierCashbackMcDetailResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return editCashierCashbackMcDetailResponseResult;
    }

    /**
     * 卡券营销活动信息编辑接口Dubbo实现
     *
     * @param editCouponMcDetailRequest 卡券营销活动信息编辑接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.EditCouponMcDetailResponse>
     * @author Jinan Liu
     * @date 2020/5/20 15:49
     */
    @Override
    public Result<EditCouponMcDetailResponse> editCouponMcDetail(EditCouponMcDetailRequest editCouponMcDetailRequest) {

        DubboService<EditCouponMcDetailRequest> dubboService = new DubboServiceImpl();
        Result<EditCouponMcDetailResponse> editCouponMcDetailResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.EDIT_CP_MC_DETAIL.getTxnNum().equals(editCouponMcDetailRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<EditCouponMcDetailResponse> dubboResult = dubboService.callAtomService(editCouponMcDetailRequest,
                    MompTxnNumEnum.EDIT_CP_MC_DETAIL.getService(), EditCouponMcDetailResponse.class);
            editCouponMcDetailResponseResult.setResult(dubboResult.getResult());
            editCouponMcDetailResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            EditCouponMcDetailResponse editCouponMcDetailResponse = new EditCouponMcDetailResponse();
            editCouponMcDetailResponseResult.setResult(editCouponMcDetailResponse);
            editCouponMcDetailResponse.setHeader(editCouponMcDetailRequest.getHeader());
            editCouponMcDetailResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                editCouponMcDetailResponse.setRespCode(((BizException) e).getCode());
                editCouponMcDetailResponse.setRespDesc(e.getMessage());
            } else {
                editCouponMcDetailResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                editCouponMcDetailResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return editCouponMcDetailResponseResult;
    }

    /**
     * 商户手续费优惠营销活动信息编辑接口Dubbo实现
     *
     * @param editMchntFeeDiscountMcDetailRequest 商户手续费优惠营销活动信息编辑接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.EditMchntFeeDiscountMcDetailResponse>
     * @author Jinan Liu
     * @date 2020/5/20 15:50
     */
    @Override
    public Result<EditMchntFeeDiscountMcDetailResponse> editMchntFeeDiscountMcDetail(EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) {

        DubboService<EditMchntFeeDiscountMcDetailRequest> dubboService = new DubboServiceImpl();
        Result<EditMchntFeeDiscountMcDetailResponse> editMchntFeeDiscountMcDetailResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.EDIT_MFD_MC_DETAIL.getTxnNum().equals(editMchntFeeDiscountMcDetailRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<EditMchntFeeDiscountMcDetailResponse> dubboResult = dubboService.callAtomService(editMchntFeeDiscountMcDetailRequest,
                    MompTxnNumEnum.EDIT_MFD_MC_DETAIL.getService(), EditMchntFeeDiscountMcDetailResponse.class);
            editMchntFeeDiscountMcDetailResponseResult.setResult(dubboResult.getResult());
            editMchntFeeDiscountMcDetailResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            EditMchntFeeDiscountMcDetailResponse editMchntFeeDiscountMcDetailResponse = new EditMchntFeeDiscountMcDetailResponse();
            editMchntFeeDiscountMcDetailResponseResult.setResult(editMchntFeeDiscountMcDetailResponse);
            editMchntFeeDiscountMcDetailResponse.setHeader(editMchntFeeDiscountMcDetailRequest.getHeader());
            editMchntFeeDiscountMcDetailResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                editMchntFeeDiscountMcDetailResponse.setRespCode(((BizException) e).getCode());
                editMchntFeeDiscountMcDetailResponse.setRespDesc(e.getMessage());
            } else {
                editMchntFeeDiscountMcDetailResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                editMchntFeeDiscountMcDetailResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return editMchntFeeDiscountMcDetailResponseResult;
    }

    /**
     * 减免类营销活动信息编辑接口Dubbo实现
     *
     * @param editMoneyOffMcDetailRequest 减免类营销活动信息编辑接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.EditMoneyOffMcDetailResponse> 减免类营销活动信息编辑接口应答对象
     * @author Jinan Liu
     * @date 2020/5/20 15:50
     */
    @Override
    public Result<EditMoneyOffMcDetailResponse> editMoneyOffMcDetail(EditMoneyOffMcDetailRequest editMoneyOffMcDetailRequest) {

        DubboService<EditMoneyOffMcDetailRequest> dubboService = new DubboServiceImpl();
        Result<EditMoneyOffMcDetailResponse> editMoneyOffMcDetailResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.EDIT_MO_MC_DETAIL.getTxnNum().equals(editMoneyOffMcDetailRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<EditMoneyOffMcDetailResponse> dubboResult = dubboService.callAtomService(editMoneyOffMcDetailRequest,
                    MompTxnNumEnum.EDIT_MO_MC_DETAIL.getService(), EditMoneyOffMcDetailResponse.class);
            editMoneyOffMcDetailResponseResult.setResult(dubboResult.getResult());
            editMoneyOffMcDetailResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            EditMoneyOffMcDetailResponse editMoneyOffMcDetailResponse = new EditMoneyOffMcDetailResponse();
            editMoneyOffMcDetailResponseResult.setResult(editMoneyOffMcDetailResponse);
            editMoneyOffMcDetailResponse.setHeader(editMoneyOffMcDetailRequest.getHeader());
            editMoneyOffMcDetailResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                editMoneyOffMcDetailResponse.setRespCode(((BizException) e).getCode());
                editMoneyOffMcDetailResponse.setRespDesc(e.getMessage());
            } else {
                editMoneyOffMcDetailResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                editMoneyOffMcDetailResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return editMoneyOffMcDetailResponseResult;
    }

    /**
     * 进行中营销活动添加商户接口Dubbo实现
     *
     * @param addMchntForToClientMcRequest 进行中活动添加商户接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.AddMchntForToClientMcResponse>
     * @author Jinan Liu
     * @date 2020/5/20 15:50
     */
    @Override
    public Result<AddMchntForToClientMcResponse> addMchntForToClientMc(AddMchntForToClientMcRequest addMchntForToClientMcRequest) {

        DubboService<AddMchntForToClientMcRequest> dubboService = new DubboServiceImpl();
        Result<AddMchntForToClientMcResponse> addMchntForToClientMcResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.ADD_MCHNT_TO_MC.getTxnNum().equals(addMchntForToClientMcRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<AddMchntForToClientMcResponse> dubboResult = dubboService.callAtomService(addMchntForToClientMcRequest,
                    MompTxnNumEnum.ADD_MCHNT_TO_MC.getService(), AddMchntForToClientMcResponse.class);
            addMchntForToClientMcResponseResult.setResult(dubboResult.getResult());
            addMchntForToClientMcResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            AddMchntForToClientMcResponse addMchntForToClientMcResponse = new AddMchntForToClientMcResponse();
            addMchntForToClientMcResponseResult.setResult(addMchntForToClientMcResponse);
            addMchntForToClientMcResponse.setHeader(addMchntForToClientMcRequest.getHeader());
            addMchntForToClientMcResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                addMchntForToClientMcResponse.setRespCode(((BizException) e).getCode());
                addMchntForToClientMcResponse.setRespDesc(e.getMessage());
            } else {
                addMchntForToClientMcResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                addMchntForToClientMcResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return addMchntForToClientMcResponseResult;
    }

    /**
     * 营销活动商户批量上传接口
     *
     * @param editMcMerListRequest 进行中活动添加商户接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.EditMcMerListResponse> 进行中活动添加商户接口应答对象
     * @author liujinan
     * @date 2021/6/28 18:54
     */
    @Override
    public Result<EditMcMerListResponse> editMcMerList(EditMcMerListRequest editMcMerListRequest) {

        DubboService<EditMcMerListRequest> dubboService = new DubboServiceImpl();
        Result<EditMcMerListResponse> editMcMerListResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.EDIT_MC_MER_LIST.getTxnNum().equals(editMcMerListRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<EditMcMerListResponse> dubboResult = dubboService.callAtomService(editMcMerListRequest,
                    MompTxnNumEnum.EDIT_MC_MER_LIST.getService(), AddMchntForToClientMcResponse.class);
            editMcMerListResponseResult.setResult(dubboResult.getResult());
            editMcMerListResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            EditMcMerListResponse editMcMerListResponse = new EditMcMerListResponse();
            editMcMerListResponseResult.setResult(editMcMerListResponse);
            editMcMerListResponse.setHeader(editMcMerListResponse.getHeader());
            editMcMerListResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                editMcMerListResponse.setRespCode(((BizException) e).getCode());
                editMcMerListResponse.setRespDesc(e.getMessage());
            } else {
                editMcMerListResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                editMcMerListResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }

        return editMcMerListResponseResult;
    }
}
